<template>
  <a-modal
    :width='1400'
    :visible='visible'
    :confirm-loading='loading'
    :title="isUpdate ? '修改' : '新建'"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible='updateVisible'
    @ok='save'
  >
  <div class="ele-body ele-body-card">
    <a-card
      :bordered="true"
      :body-style="{padding: '20px'}">
      <a-form
        ref="form"
        :model="paramForm"
        :rules="rules"
        :label-col="{ md: { span: 11 }, sm: { span: 24 } }"
        :wrapper-col="{ md: { span: 13 }, sm: { span: 24 } }"
      >
        <a-row :gutter="8">
          <a-col :md="10" :sm="24" :xs="24">
            <a-form-item label='模板名称:' name='templateName'>
              <a-input v-model:value='form.templateName' allow-clear style="width: 300px;" />
            </a-form-item>
          </a-col>
          <a-col :md="1" :sm="24" :xs="24" />
          <a-col :md="4" :sm="24" :xs="24" >
            <a-form-item v-if="!isUpdate">
              <a-button type='primary' html-type='button' @click='syncSetting'>
                一键同步已有设备的配置
              </a-button>
            </a-form-item>
          </a-col>
          <a-col :md="9" :sm="24" :xs="24" />
        </a-row>
        <a-divider>总开关</a-divider>
        <a-row :gutter='8'>
          <a-col :md='12' :sm='24' :xs='24'>
            <a-form-item label='总开关' name='masterSwitch'>
              <a-switch
                checked-children='开'
                un-checked-children='关'
                autoFocus='false'
                :checked='paramForm.switch.masterSwitchCheck'
                @change='masterSwitchChange'
              />
            </a-form-item>
          </a-col>

          <a-col :md='12' :sm='24' :xs='24'>
            <a-form-item label='冬夏季模式' name='seasonMode'>
              <a-radio-group v-model:value='form.seasonMode'>
                <a-radio :value='1'>
                  夏季模式
                </a-radio>
                <a-radio :value='2'>
                  冬季模式
                </a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>
        </a-row>
        <a-divider>进出水参数</a-divider>
        <a-row :gutter='8'>
          <a-col :md='12' :sm='24' :xs='24'>
            <a-form-item label='设定设备检修状态' name='repairMode'>
              <a-radio-group v-model:value='form.repairMode'>
                <a-radio :value='1'>
                  正常工作
                </a-radio>
                <a-radio :value='2'>
                  维修中，维修的时候不做任何判断报警
                </a-radio>
              </a-radio-group>
            </a-form-item>
            <a-form-item label='进出水瞬时流量差值的报警门限:' name='differVolume'>
              <a-input style="width: 80%" v-model:value='form.differVolume' placeholder='' allow-clear />
              <a-alert message="整数，若实际流量差 超过此门限，代表有饮水槽漏水的情况" style="margin-top:5px;font-size: 11px;padding:2px 3px;width: 80%" type="info" show-icon />
            </a-form-item>
            <a-form-item label="现场告警声光报警器的告警模式:" name="sgwarnMode">
              <a-select style="width: 80%" v-model:value="form.sgwarnMode">
                <a-select-option :value="0">不使用声光报警器</a-select-option>
                <a-select-option :value="1">声光报警器一直报警，直到报警消除</a-select-option>
                <a-select-option :value="2">声光报警器响xx秒，停yy秒</a-select-option>
                <a-select-option :value="3">响xx秒后就不再告警</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label='现场告警声光报警器动作时长(秒):' name='sgwarnActionTime'>
              <a-input style="width: 80%" v-model:value='form.sgwarnActionTime' placeholder='单位秒，只有在告警模式是2或者3的时候起作用' allow-clear />
              <a-alert message="整数，单位秒，只有在告警模式是2或者3的时候起作用" style="margin-top:5px;font-size: 11px;padding:2px 3px;width: 80%;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='现场告警声光报警器停止时长(秒):' name='sgwarnStopTime'>
              <a-input style="width: 80%" v-model:value='form.sgwarnStopTime' placeholder='单位秒' allow-clear />
              <a-alert message="整数，单位秒，只有在告警模式是2的时候起作用" style="margin-top:5px;font-size: 11px;padding:2px 3px;width: 80%;" type="info" show-icon />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24' :xs='24' >
            <a-form-item label='进水温度补偿因子:' name='influentTempOffset'>
              <a-input style="width: 80%" v-model:value='form.influentTempOffset' placeholder='' allow-clear />
              <a-alert message="单位℃，精确到小数点后一位" style="margin-top:5px;font-size: 11px;padding:2px 3px;width: 80%;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='出水温度补偿因子:' name='effluentTempOffset'>
              <a-input style="width: 80%" v-model:value='form.effluentTempOffset' placeholder='' allow-clear />
              <a-alert message="单位℃，精确到小数点后一位" style="margin-top:5px;font-size: 11px;padding:2px 3px;width: 80%;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='报警检测时长:' name='warnCheckTime'>
              <a-input style="width: 80%" v-model:value='form.warnCheckTime' placeholder='（范围从0到32767）单位秒' allow-clear />
              <a-alert message="整数,（范围从0到32767）单位秒" style="margin-top:5px;font-size: 11px;padding:2px 3px;width: 80%;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='报警手动复位后停止检测的时长:' name='warnRstStopcheckTime'>
              <a-input style="width: 80%" v-model:value='form.warnRstStopcheckTime' placeholder='单位分钟，整数' allow-clear />
              <a-alert message="单位分钟，整数" style="margin-top:5px;font-size: 11px;padding:2px 3px;width: 80%;" type="info" show-icon />
            </a-form-item>
          </a-col>
        </a-row>

        <a-divider>告警设置</a-divider>
        <a-row>
          <a-col :md='12' :sm='24' :xs='24'>
            <a-form-item label='进水温度报警下限(℃):' name='influentTempAlarmLow'>
              <a-input v-model:value='form.influentTempAlarmLow' placeholder='精确到小数点后1位,范围从-500到900' allow-clear />
              <a-alert message="精确到小数点后1位,范围从-500到900" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='进水温度报警上限(℃):' name='influentTempAlarmHigh'>
              <a-input v-model:value='form.influentTempAlarmHigh' placeholder='精确到小数点后1位,范围从-500到900' allow-clear />
              <a-alert message="精确到小数点后1位,范围从-500到900" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='进水瞬时流量报警下限:' name='influentMonetFlowAlarmLow'>
              <a-input v-model:value='form.influentMonetFlowAlarmLow' placeholder='整数，范围从0到32767' allow-clear />
              <a-alert message="整数，范围从0到32767" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='进水瞬时流量报警上限:' name='influentMonetFlowAlarmHigh'>
              <a-input v-model:value='form.influentMonetFlowAlarmHigh' placeholder='整数，范围从0到32767' allow-clear />
              <a-alert message="整数，范围从0到327670" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24' :xs='24'>
            <a-form-item label='出水温度报警下限(℃):' name='effluentTempAlarmLow'>
              <a-input v-model:value='form.effluentTempAlarmLow' placeholder='精确到小数点后1位,范围从-500到900' allow-clear />
              <a-alert message="精确到小数点后1位,范围从-500到900" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='出水温度报警上限(℃):' name='effluentTempAlarmHigh'>
              <a-input v-model:value='form.effluentTempAlarmHigh' placeholder='精确到小数点后1位,范围从-500到900' allow-clear />
              <a-alert message="精确到小数点后1位,范围从-500到900" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='出水瞬时流量报警下限:' name='effluentMonetFlowAlarmLow'>
              <a-input v-model:value='form.effluentMonetFlowAlarmLow' placeholder='整数，范围从0到32767' allow-clear />
              <a-alert message="整数，范围从0到32767" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='出水瞬时流量报警上限:' name='effluentMonetFlowAlarmHigh'>
              <a-input v-model:value='form.effluentMonetFlowAlarmHigh' placeholder='整数，范围从0到32767' allow-clear />
              <a-alert message="整数，范围从0到327670" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
          </a-col>
        </a-row>
        <!---------------- 计次模式下的时间段设置----------->
        <a-divider orientation="left"><a-tooltip color='orange' title=''>小计流量差数据设置</a-tooltip></a-divider>
        <a-alert message="时间块大小的单位分钟，范围是5到1440；流量差门限，单位0.01立方米" type="warning" />
        <a-row :gutter="8" style="margin-top : 20px;">
          <a-col :md="8" :sm="24" :xs="24">
            <a-form-item label="小计流量一的时间块大小:" name="SUBTOTAL1_TIME">
              <a-input-number :min="3" :max="1440" v-model:value="flowDiffJsonForm.SUBTOTAL1_TIME" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="小计流量一的时间块大小:" name="SUBTOTAL2_TIME">
              <a-input-number :min="3" :max="1440" v-model:value="flowDiffJsonForm.SUBTOTAL2_TIME" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="小计流量一的时间块大小:" name="SUBTOTAL3_TIME">
              <a-input-number :min="3" :max="1440" v-model:value="flowDiffJsonForm.SUBTOTAL3_TIME" placeholder="" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24" :xs="24">
            <a-form-item label="流量差门限:" name="SUBTOTAL1_DIFFER">
              <a-input v-model:value="flowDiffJsonForm.SUBTOTAL1_DIFFER" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="流量差门限:" name="SUBTOTAL2_DIFFER">
              <a-input v-model:value="flowDiffJsonForm.SUBTOTAL2_DIFFER" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="流量差门限:" name="SUBTOTAL3_DIFFER">
              <a-input v-model:value="flowDiffJsonForm.SUBTOTAL3_DIFFER" placeholder="" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24" :xs="24" >
            <a-form-item label="使能状态:" name="SUBTOTAL1_VALID">
              <a-select v-model:value="flowDiffJsonForm.SUBTOTAL1_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="SUBTOTAL2_VALID">
              <a-select v-model:value="flowDiffJsonForm.SUBTOTAL2_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="SUBTOTAL3_VALID">
              <a-select v-model:value="flowDiffJsonForm.SUBTOTAL3_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24" :xs="24" />
        </a-row>
        <a-row :gutter="8" style="margin-top : 20px;">
          <a-col :md="8" :sm="24" :xs="24">
            <a-form-item label="小计流量一的时间块大小:" name="SUBTOTAL1_TIME">
              <a-input-number :min="3" :max="1440" v-model:value="flowDiffJsonForm.SUBTOTAL1_TIME" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="小计流量一的时间块大小:" name="SUBTOTAL2_TIME">
              <a-input-number :min="3" :max="1440" v-model:value="flowDiffJsonForm.SUBTOTAL2_TIME" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="小计流量一的时间块大小:" name="SUBTOTAL3_TIME">
              <a-input-number :min="3" :max="1440" v-model:value="flowDiffJsonForm.SUBTOTAL3_TIME" placeholder="" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24" :xs="24">
            <a-form-item label="流量差门限:" name="SUBTOTAL1_DIFFER">
              <a-input v-model:value="flowDiffJsonForm.SUBTOTAL1_DIFFER" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="流量差门限:" name="SUBTOTAL2_DIFFER">
              <a-input v-model:value="flowDiffJsonForm.SUBTOTAL2_DIFFER" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="流量差门限:" name="SUBTOTAL3_DIFFER">
              <a-input v-model:value="flowDiffJsonForm.SUBTOTAL3_DIFFER" placeholder="" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24" :xs="24" >
            <a-form-item label="使能状态:" name="SUBTOTAL1_VALID">
              <a-select v-model:value="flowDiffJsonForm.SUBTOTAL1_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="SUBTOTAL2_VALID">
              <a-select v-model:value="flowDiffJsonForm.SUBTOTAL2_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="SUBTOTAL3_VALID">
              <a-select v-model:value="flowDiffJsonForm.SUBTOTAL3_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24" :xs="24" />
        </a-row>

        <!---------------- 饮水低谷时段的时间段设置----------->
        <a-divider orientation="left"><a-tooltip color='orange' title=''>饮水低谷时段数据设置</a-tooltip></a-divider>
        <a-row :gutter="8">
          <a-col :md="8" :sm="24" :xs="24">
            <a-form-item label="时间段一开始时间:" name="VALLEY_TIME1_START">
              <a-time-picker v-model:value="paramForm.VALLEY_TIME1_START" format="HH:mm" @change="selectValleyTime1Start"  allow-clear  />
            </a-form-item>
            <a-form-item label="时间段二开始时间:" name="VALLEY_TIME2_START">
              <a-time-picker v-model:value="paramForm.VALLEY_TIME2_START" format="HH:mm" @change="selectValleyTime2Start" allow-clear />
            </a-form-item>
            <a-form-item label="时间段三开始时间:" name="VALLEY_TIME3_START">
              <a-time-picker v-model:value="paramForm.VALLEY_TIME3_START" format="HH:mm" @change="selectValleyTime3Start" allow-clear />
            </a-form-item>
            <a-form-item label="时间段四开始时间:" name="VALLEY_TIME4_START">
              <a-time-picker v-model:value="paramForm.VALLEY_TIME4_START" format="HH:mm" @change="selectValleyTime4Start" allow-clear />
            </a-form-item>
            <a-form-item label='饮水低谷时段温度报警下限:' name='WARN_VALLEY_TEMP_LOW'>
              <a-input v-model:value='warnValleyJsonForm.WARN_VALLEY_TEMP_LOW' placeholder='饮水低谷时段温度报警下限' allow-clear />
              <a-alert message="精确到小数点后1位,范围从-500到900" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
          </a-col>
          <a-col :md="7" :sm="24" :xs="24">
            <a-form-item label="结束时间(截止24:00):" name="VALLEY_TIME1_OVER">
              <time24-select :value="paramForm.VALLEY_TIME1_OVER" @modify="selectValley1Over" />
            </a-form-item>
            <a-form-item label="结束时间(截止24:00):" name="VALLEY_TIME2_OVER">
              <time24-select :value="paramForm.VALLEY_TIME2_OVER" @modify="selectValley2Over" />
            </a-form-item>
            <a-form-item label="结束时间(截止24:00):" name="VALLEY_TIME3_OVER">
              <time24-select :value="paramForm.VALLEY_TIME3_OVER" @modify="selectValley3Over" />
            </a-form-item>
            <a-form-item label="结束时间(截止24:00):" name="VALLEY_TIME4_OVER">
              <time24-select :value="paramForm.VALLEY_TIME4_OVER" @modify="selectValley4Over" />
            </a-form-item>
          </a-col>
          <a-col :md="9" :sm="24" :xs="24" />
        </a-row>
      </a-form>
    </a-card>
    <DeviceDrinkheartingFirmwareConfigTemplateSyncsetting v-if="showSelectDevice"
                                                               v-model:visible="showSelectDevice"
                                                               :data="current"
                                                               @done="synctoDevice" />
  </div>
  </a-modal>
</template>

<script>
import { message } from 'ant-design-vue';
import Time24Select from '@/components/Time24Select/Time24Select.vue';
import dayjs from "dayjs";
import {DeviceDrinkheatingConfigTemplateApi} from "@/api/property/drinkhearting/DeviceDrinkheatingConfigTemplateApi";
import {DeviceDrinkheatingConfigApi} from "@/api/property/drinkhearting/DeviceDrinkheatingConfigApi";
import DeviceDrinkheartingFirmwareConfigTemplateSyncsetting from './drinkhearting-firmware-config-template-syncsetting.vue'
export default {
  name: 'DeviceDrinkheartingFirmwareConfigTemplateEdit',
  components: {
    Time24Select,
    DeviceDrinkheartingFirmwareConfigTemplateSyncsetting
  },
  emits: ['done', 'update:visible'],
  props: {
    // 弹窗是否打开
    visible: Boolean,
    data: Object
  },
  created() {
    if (this.data) {
      this.form = Object.assign({}, this.data);
      this.paramForm.switch = {};
      this.isUpdate = true;
      this.init(this.data);
    } else {
      this.form = {};
      this.paramForm.switch = {};
      this.isUpdate = false;
    }
  },
  data() {
    return {
      form : {},
      paramForm : {},
      flowDiffJsonForm : {},
      warnValleyJsonForm : {},
      rules: {

      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      showSelectDevice : false,
      current : null
    };
  },
  methods: {
    updateVisible(value) {
      this.$emit('update:visible', value);
    },
    syncSetting() {
      console.log(this.form);
      this.current = this.form;
      this.showSelectDevice = true;
    },
    synctoDevice (recordId) {
      let that = this;
      DeviceDrinkheatingConfigApi.detail({"recordId" : recordId}).then(res => {
        delete res.recordId;
        delete res.updateTime;
        delete res.updateUser;
        delete res.createTime;
        delete res.createUser;
        res.templateName = that.form.templateName;
        that.init(res);
      }).catch((e) => {
        console.log(e);
      });
    },
    masterSwitchChange(checked) {
      console.log(checked);
      this.paramForm.switch.masterSwitchCheck = checked;
    },
    init(initData) {
      let _conf = initData;
      if (_conf) {
        this.form = _conf;
        let flowDiffJson = Object.assign({}, (_conf.flowDiffJson ? (JSON.parse(_conf.flowDiffJson) || {}) : {}));
        this.flowDiffJsonForm = flowDiffJson;
        if (flowDiffJson) {
          //转成数字
          this.flowDiffJsonForm.SUBTOTAL1_TIME = flowDiffJson.SUBTOTAL1_TIME ? Number(flowDiffJson.SUBTOTAL1_TIME) : 0;
          this.flowDiffJsonForm.SUBTOTAL2_TIME = flowDiffJson.SUBTOTAL2_TIME ? Number(flowDiffJson.SUBTOTAL2_TIME) : 0;
          this.flowDiffJsonForm.SUBTOTAL3_TIME = flowDiffJson.SUBTOTAL3_TIME ? Number(flowDiffJson.SUBTOTAL3_TIME) : 0;
          //使能状态
          this.flowDiffJsonForm.SUBTOTAL1_VALID = flowDiffJson.SUBTOTAL1_VALID ? Number(flowDiffJson.SUBTOTAL1_VALID) : 0;
          this.flowDiffJsonForm.SUBTOTAL2_VALID = flowDiffJson.SUBTOTAL2_VALID ? Number(flowDiffJson.SUBTOTAL2_VALID) : 0;
          this.flowDiffJsonForm.SUBTOTAL3_VALID = flowDiffJson.SUBTOTAL3_VALID ? Number(flowDiffJson.SUBTOTAL3_VALID) : 0;
        }

        let warnValleyJson = Object.assign({}, (_conf.warnValleyJson ? (JSON.parse(_conf.warnValleyJson) || {}) : {}));
        this.warnValleyJsonForm = warnValleyJson;
        if (warnValleyJson) {
          let _VALLEY_TIME1_START_HOUR = warnValleyJson.VALLEY_TIME1_START_HOUR ? Number(warnValleyJson.VALLEY_TIME1_START_HOUR) : 0,
            _VALLEY_TIME1_START_MIN = warnValleyJson.VALLEY_TIME1_START_MIN ? Number(warnValleyJson.VALLEY_TIME1_START_MIN) : 0,
            _VALLEY_TIME1_OVER_HOUR = warnValleyJson.VALLEY_TIME1_OVER_HOUR ? Number(warnValleyJson.VALLEY_TIME1_OVER_HOUR) : 0,
            _VALLEY_TIME1_OVER_MIN = warnValleyJson.VALLEY_TIME1_OVER_MIN ? Number(warnValleyJson.VALLEY_TIME1_OVER_MIN) : 0;
          this.paramForm.VALLEY_TIME1_START= dayjs( ((_VALLEY_TIME1_START_HOUR < 10 ? ("0" + _VALLEY_TIME1_START_HOUR) : _VALLEY_TIME1_START_HOUR) + ":" + (_VALLEY_TIME1_START_MIN < 10 ? ("0" + _VALLEY_TIME1_START_MIN) : _VALLEY_TIME1_START_MIN)), 'HH:mm');
          this.paramForm.VALLEY_TIME1_OVER = [_VALLEY_TIME1_OVER_HOUR, _VALLEY_TIME1_OVER_MIN];

          let _VALLEY_TIME2_START_HOUR = warnValleyJson.VALLEY_TIME2_START_HOUR ? Number(warnValleyJson.VALLEY_TIME2_START_HOUR) : 0,
            _VALLEY_TIME2_START_MIN = warnValleyJson.VALLEY_TIME2_START_MIN ? Number(warnValleyJson.VALLEY_TIME2_START_MIN) : 0,
            _VALLEY_TIME2_OVER_HOUR = warnValleyJson.VALLEY_TIME2_OVER_HOUR ? Number(warnValleyJson.VALLEY_TIME2_OVER_HOUR) : 0,
            _VALLEY_TIME2_OVER_MIN = warnValleyJson.VALLEY_TIME2_OVER_MIN ? Number(warnValleyJson.VALLEY_TIME2_OVER_MIN) : 0;
          this.paramForm.VALLEY_TIME2_START= dayjs( ((_VALLEY_TIME2_START_HOUR < 10 ? ("0" + _VALLEY_TIME2_START_HOUR) : _VALLEY_TIME2_START_HOUR) + ":" + (_VALLEY_TIME2_START_MIN < 10 ? ("0" + _VALLEY_TIME2_START_MIN) : _VALLEY_TIME2_START_MIN)), 'HH:mm');
          this.paramForm.VALLEY_TIME2_OVER = [_VALLEY_TIME2_OVER_HOUR, _VALLEY_TIME2_OVER_MIN];

          let _VALLEY_TIME3_START_HOUR = warnValleyJson.VALLEY_TIME3_START_HOUR ? Number(warnValleyJson.VALLEY_TIME3_START_HOUR) : 0,
            _VALLEY_TIME3_START_MIN = warnValleyJson.VALLEY_TIME3_START_MIN ? Number(warnValleyJson.VALLEY_TIME3_START_MIN) : 0,
            _VALLEY_TIME3_OVER_HOUR = warnValleyJson.VALLEY_TIME3_OVER_HOUR ? Number(warnValleyJson.VALLEY_TIME3_OVER_HOUR) : 0,
            _VALLEY_TIME3_OVER_MIN = warnValleyJson.VALLEY_TIME3_OVER_MIN ? Number(warnValleyJson.VALLEY_TIME3_OVER_MIN) : 0;
          this.paramForm.VALLEY_TIME3_START= dayjs( ((_VALLEY_TIME3_START_HOUR < 10 ? ("0" + _VALLEY_TIME3_START_HOUR) : _VALLEY_TIME3_START_HOUR) + ":" + (_VALLEY_TIME3_START_MIN < 10 ? ("0" + _VALLEY_TIME3_START_MIN) : _VALLEY_TIME3_START_MIN)), 'HH:mm');
          this.paramForm.VALLEY_TIME3_OVER = [_VALLEY_TIME3_OVER_HOUR, _VALLEY_TIME3_OVER_MIN];

          let _VALLEY_TIME4_START_HOUR = warnValleyJson.VALLEY_TIME4_START_HOUR ? Number(warnValleyJson.VALLEY_TIME4_START_HOUR) : 0,
            _VALLEY_TIME4_START_MIN = warnValleyJson.VALLEY_TIME4_START_MIN ? Number(warnValleyJson.VALLEY_TIME4_START_MIN) : 0,
            _VALLEY_TIME4_OVER_HOUR = warnValleyJson.VALLEY_TIME4_OVER_HOUR ? Number(warnValleyJson.VALLEY_TIME4_OVER_HOUR) : 0,
            _VALLEY_TIME4_OVER_MIN = warnValleyJson.VALLEY_TIME4_OVER_MIN ? Number(warnValleyJson.VALLEY_TIME4_OVER_MIN) : 0;
          this.paramForm.VALLEY_TIME4_START= dayjs( ((_VALLEY_TIME4_START_HOUR < 10 ? ("0" + _VALLEY_TIME4_START_HOUR) : _VALLEY_TIME4_START_HOUR) + ":" + (_VALLEY_TIME4_START_MIN < 10 ? ("0" + _VALLEY_TIME4_START_MIN) : _VALLEY_TIME4_START_MIN)), 'HH:mm');
          this.paramForm.VALLEY_TIME4_OVER = [_VALLEY_TIME4_OVER_HOUR, _VALLEY_TIME4_OVER_MIN];
        }


      }
    },

    selectValleyTime1Start(time) {
      this.warnValleyJsonForm.VALLEY_TIME1_START_HOUR = time.hour();
      this.warnValleyJsonForm.VALLEY_TIME1_START_MIN = time.minute();
    },
    selectValleyTime2Start(time) {
      this.warnValleyJsonForm.VALLEY_TIME2_START_HOUR = time.hour();
      this.warnValleyJsonForm.VALLEY_TIME2_START_MIN = time.minute();
    },
    selectValleyTime3Start(time) {
      this.warnValleyJsonForm.VALLEY_TIME3_START_HOUR = time.hour();
      this.warnValleyJsonForm.VALLEY_TIME3_START_MIN = time.minute();
    },
    selectValleyTime4Start(time) {
      this.warnValleyJsonForm.VALLEY_TIME4_START_HOUR = time.hour();
      this.warnValleyJsonForm.VALLEY_TIME4_START_MIN = time.minute();
    },

    selectValley1Over(time) {
      this.paramForm.VALLEY_TIME1_OVER = time;
      if (time) {
        this.warnValleyJsonForm.VALLEY_TIME1_OVER_HOUR = time[0];
        this.warnValleyJsonForm.VALLEY_TIME1_OVER_MIN = time[1];
      }
    },

    selectValley2Over(time) {
      this.paramForm.VALLEY_TIME2_OVER = time;
      if (time) {
        this.warnValleyJsonForm.VALLEY_TIME2_OVER_HOUR = time[0];
        this.warnValleyJsonForm.VALLEY_TIME2_OVER_MIN = time[1];
      }
    },

    selectValley3Over(time) {
      this.paramForm.VALLEY_TIME3_OVER = time;
      if (time) {
        this.warnValleyJsonForm.VALLEY_TIME3_OVER_HOUR = time[0];
        this.warnValleyJsonForm.VALLEY_TIME3_OVER_MIN = time[1];
      }
    },

    selectValley4Over(time) {
      this.paramForm.VALLEY_TIME4_OVER = time;
      if (time) {
        this.warnValleyJsonForm.VALLEY_TIME4_OVER_HOUR = time[0];
        this.warnValleyJsonForm.VALLEY_TIME4_OVER_MIN = time[1];
      }
    },



    /**
     * 保存和编辑
     * 写到队列，队列发送完回写到原配置
     * @author cancan
     * @date 2022/03/04 21:15
     */
    save() {
      //将"结束时间"00：00转为24点吧。this.timeConfForm.TIME6_OVER_HOUR结束
      let flowDiffJson = this.flowDiffJsonForm;
      let warnValleyJsonForm = this.warnValleyJsonForm;
      console.log(flowDiffJson);

      this.form.masterSwitch = this.paramForm.switch.masterSwitchCheck ? 1 : 2;
      this.form.flowDiffJson = JSON.stringify(flowDiffJson);
      this.form.warnValleyJsonForm = JSON.stringify(warnValleyJsonForm);
      // 修改加载框为正在加载
      this.loading = true;
      let result = null;
      // 执行编辑或修改
      if (this.isUpdate) {
        result = DeviceDrinkheatingConfigTemplateApi.edit(this.form);
      } else {
        result = DeviceDrinkheatingConfigTemplateApi.add(this.form);
      }
      result.then(res => {
          // 移除加载框
          this.loading = false;
          // 提示添加成功
          message.success(res.message);
          // 如果是新增，则form表单置空
          if (!this.isUpdate) {
            this.form = {};
          }
          // 关闭弹框，通过控制visible的值，传递给父组件
          this.updateVisible(false);
          // 触发父组件done事件
          this.$emit('done');
        })
        .catch(() => {
          this.loading = false;
        });
    }
  }
};
</script>
<style scoped>
/** 用户卡片 */
.workplace-user-card .ele-cell-content {
  overflow: hidden;
}

.workplace-user-card h4 {
  margin-bottom: 6px;
}
.regionclass /deep/ .ant-col-md-11 {
  max-width : 30% !important;
}
.regionclass /deep/ .ant-col-md-13 {
  max-width: 70% !important;
}
</style>
